package ve.com.wayoyo.wuml_case.DibujoDiagramas;

import ve.com.wayoyo.wuml_case.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class AtributoComponente extends Dialog {

	EditText etName;
	private String hint;
	private String modificador;
	private String nombreVariable;
	private String tipoDato;

	public AtributoComponente(Context context) {
		super(context);
	}
	
	public void alert(String mensaje)
	{
		Toast.makeText(this.getContext(), mensaje , Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.atributo_componente_layout);
		setTitle("Nuevo Atributo");
		this.setModificadores();		
		this.setok();
//		etName = (EditText) findViewById(R.id.nombreAtributoNuevo);
//		etName.setHint(this.hint);
	}
	
	public void setModificadores()
	{
		Spinner s = (Spinner) findViewById(R.id.spinner);
		final String[] array_spinner = new String[3];
		array_spinner[0] = "Public";
		array_spinner[1] = "Private";
		array_spinner[2] = "Protected";

		ArrayAdapter<?> adapter = new ArrayAdapter<Object>(this.getContext(),
				android.R.layout.simple_spinner_item, array_spinner);
		s.setAdapter(adapter);
		s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
		{
		    public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
		    {
		    	modificador= array_spinner[position];
		    }

			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}

		});

	}

	public void setok(){
		Button buttonOK = (Button) findViewById(R.id.btAtributo);
		buttonOK.setText("Agregar");
		buttonOK.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				nombreVariable = ((EditText) findViewById(R.id.nombreAtributoNuevo)).getText().toString();
				tipoDato = ((EditText) findViewById(R.id.nuevoTipoDato)).getText().toString();
				VistaDiagrama vista = VistaDiagrama.getVista();
				CompAtributo comp = new CompAtributo(nombreVariable,modificador.toLowerCase(),tipoDato);
				Diagrama diag = vista.getDiagrama();
				((DiagramaClases) diag).agregarAtributo(comp);
				vista.invalidate();
				AtributoComponente.this.dismiss();
			}
		});

	}
}